package cn.iocoder.yudao.module.infra.embedding;

import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import jakarta.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Slf4j
@Component
public class EmbeddingServiceFactory {
    private final Map<String, IEmbeddingService> serviceMap = new HashMap<>();
    @Resource
    private EmbeddingConfig embeddingConfig;

    @Autowired
    public EmbeddingServiceFactory(Map<String, IEmbeddingService> map) {
        this.serviceMap.putAll(map);
    }

    @PostConstruct
    public void init() {
        log.info("初始化Embedding服务, primary = {}", embeddingConfig.getPrimary());
    }

    public IEmbeddingService getService() {
        final String primary = embeddingConfig.getPrimary();
        return serviceMap.get("embedding-" + primary);
    }
}
